package sjtu.ist.warehouse4ws.dao;

import java.util.List;

import sjtu.ist.warehouse4ws.model.User;

public class UserDaoHibernate extends BaseDaoHibernate implements UserDao{

	public User get(String id) {
		return (User)getHibernateTemplate().get(User.class, id);
	}

	public void save(User user) {
		
		getHibernateTemplate().save(user);
	}

	public void update(User user) {
		
		getHibernateTemplate().update(user);
	}

	public void delete(String id) {
		
		getHibernateTemplate().delete(get(id));
	}

	public void delete(User user) {
		
		getHibernateTemplate().delete(user);
	}

	public List<User> findByName(String name) {

		return (List<User>)getHibernateTemplate().find("from User u where u.name='"+name+"'");
	}

	@Override
	public List<User> findByCompany(String companyId) {
		return (List<User>)getHibernateTemplate().find("from User u where u.company='"+companyId+"'");
	}

	@Override
	public List<User> findAllUser() {
		return (List<User>)getHibernateTemplate().find("from User");
	}

	@Override
	public List<User> findUserByCompany(String companyName, int type) {
		return getHibernateTemplate().find("from User u where u.company='"+companyName+"'and u.type=2");
	}

}
